<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page language="java" import="com.uft.utils.*,java.util.*,com.uft.model.dao.*,com.uft.model.entity.*"
	errorPage="error.jsp"
%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ page isELIgnored="false"%>
<%
PreferencesDAO preferencesDAO =(PreferencesDAO)request.getAttribute("preferencesDAO");
%>
<script>
$( ".column" ).sortable({
    connectWith: ".column",
    handle: ".portlet-header",
    cancel: ".portlet-toggle",
    placeholder: "portlet-placeholder ui-corner-all"
  });
$( ".portlet" )
	.addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
	.find( ".portlet-header" )
	  .addClass( "ui-widget-header ui-corner-all" )
	  .prepend( "<span class='ui-icon ui-icon-minusthick portlet-toggle'></span>");
$( ".portlet-toggle" ).click(function() {
		 var icon = $( this );
		 icon.toggleClass( "ui-icon-minusthick ui-icon-plusthick" );
	icon.closest( ".portlet" ).find( ".portlet-content" ).toggle();
});


function updateOrAddPreference(id,category, inputId){
	var url="addPreference.htm";
	if(!!id){
		var url="updatePreference.htm";
	}
	if (!$('#'+inputId).length) {
		generateDiag("center","error", "Input is not select");
		return ;
	}
	console.log($('#'+inputId).attr('name'))
	console.log($('#'+inputId).val())
	$.ajax({
  	  type: "POST",
  	  dataType: 'json',
  	  url: url,
  	  data: {
  		preferenceId:id,
  		prefCategory:category,
  		prefName: $('#'+inputId).attr('name'),
  		prefValue: $('#'+inputId).val(),
  	  },
  	  success: function(result){

  		  if (result.Result == "OK") {
  			  generateDiag("center","success", "Success!");
  		  }else{
  			  generateDiag("center","error", result.Message);
  		  }
  	  },
  	  error: function () {
  		  generateDiag("center","error", "Error Connecting Server");
  	  }
  	  
  	});
	
}

</script>
<div class="column">
	<div class="portlet">
		<div class="portlet-header">
			WebSphere Deployments
		</div>
		<div class="portlet-content">
			<table width="100%">
				<tr><td> 
						<input type='hidden' name="CATEGORY" value="DEPLOYMENT"/>
					</td><td></td><td></td></tr>
				<%
					Preferences scriptPathPref=preferencesDAO.getPreferencesByCategoryName("DEPLOYMENT", "scriptPath");
				    out.println("<tr>");
				    out.println("<td> Deployment ScriptPath: </td>");
					if( scriptPathPref != null){
						out.println("<td> <input type='text' id='pref_scriptPath' name='"+scriptPathPref.getPrefName()+"' value='"+scriptPathPref.getPrefValue()+"' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'"+scriptPathPref.getPreferenceId()+"\',\'DEPLOYMENT\',\'pref_scriptPath\')\"></span></td>");
					}else{
						out.println("<td> <input type='text' id='pref_scriptPath' name='scriptPath' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'\',\'DEPLOYMENT\',\'pref_scriptPath\')\"></span></td>");
					}
				   
				   out.println("</tr>");
				   Preferences wasWsadminClasspath=preferencesDAO.getPreferencesByCategoryName("DEPLOYMENT", "WAS_WSADMIN_CLASSPATH");
				    out.println("<tr>");
				    out.println("<td> Wsadmin Classpath: </td>");
					if( wasWsadminClasspath != null){
						out.println("<td> <input type='text' id='pref_wasWsadminClasspath' name='"+wasWsadminClasspath.getPrefName()+"' value='"+wasWsadminClasspath.getPrefValue()+"' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'"+wasWsadminClasspath.getPreferenceId()+"\',\'DEPLOYMENT\',\'pref_scriptPath\')\"></span></td>");
					}else{
						out.println("<td> <input type='text' id='pref_wasWsadminClasspath' name='WAS_WSADMIN_CLASSPATH' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'\',\'DEPLOYMENT\',\'pref_wasWsadminClasspath\')\"></span></td>");
					}
				   
				   out.println("</tr>");
				%>
			</table>
		</div>
	</div>
	<div class="portlet">
		<div class="portlet-header">
			Application/Server
		</div>
		<div class="portlet-content">
			<table width="100%">
				<tr><td> 
						<input type='hidden' name="CATEGORY" value="APPLICATION"/>
					</td><td></td><td></td></tr>
				<%
					Preferences serverPre=preferencesDAO.getPreferencesByCategoryName("APPLICATION", "SERVER_PREFIX");
				    out.println("<tr>");
				    out.println("<td> Server Prefix: </td>");
					if( serverPre != null){
						out.println("<td> <input type='text' id='pref_serverPre' name='"+serverPre.getPrefName()+"' value='"+serverPre.getPrefValue()+"' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'"+serverPre.getPreferenceId()+"\',\'APPLICATION\',\'pref_serverPre\')\"></span></td>");
					}else{
						out.println("<td> <input type='text' id='pref_serverPre' name='SERVER_PREFIX' value='' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'\',\'APPLICATION\',\'pref_serverPre\')\"></span></td>");
					}
				   out.println("</tr>");
				   
				   Preferences serverSuf=preferencesDAO.getPreferencesByCategoryName("APPLICATION", "SERVER_SUFFIX");
				   out.println("<tr>");
				   out.println("<td> Server Suffix: </td>");
					if( serverSuf != null){
						out.println("<td> <input type='text' id='pref_serverSuf' name='"+serverSuf.getPrefName()+"' value='"+serverSuf.getPrefValue()+"' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'"+serverSuf.getPreferenceId()+"\',\'APPLICATION\',\'pref_serverSuf\')\"></span></td>");
					}else{
						out.println("<td> <input type='text'  id='pref_serverSuf' name='SERVER_SUFFIX' value='' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'\',\'APPLICATION\',\'pref_serverSuf\')\"></span></td>");
					}
				   out.println("</tr>");
				%>
			</table>
		</div>
	</div>
	<div class="portlet" >
		<div class="portlet-header">
			Security
		</div>
		<div class="portlet-content">
			<table width="100%">
					<tr><td> 
						<input type='hidden' name="CATEGORY" value="SECURITY"/>
					</td><td></td><td></td></tr>
				<%
					Preferences soapConfigProp=preferencesDAO.getPreferencesByCategoryName("SECURITY", "SOAP_CONFIG_PROP");
				    out.println("<tr>");
				    out.println("<td> SOAP Configuration File: </td>");
					if( soapConfigProp != null){
						out.println("<td> <input type='text' id='pref_soapConfigProp'  name='"+soapConfigProp.getPrefName()+"' value='"+soapConfigProp.getPrefValue()+"' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'"+soapConfigProp.getPreferenceId()+"\',\'SECURITY\',\'pref_soapConfigProp\')\"></span></td>");
					}else{
						out.println("<td> <input type='text' id='pref_soapConfigProp' name='SOAP_CONFIG_PROP' value='' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'\',\'SECURITY\',\'pref_soapConfigProp\')\"></span></td>");
					}
				   out.println("</tr>");
				   
				   Preferences sslConfigProp=preferencesDAO.getPreferencesByCategoryName("SECURITY", "SSL_CONFIG_PROP");
				   out.println("<tr>");
				    out.println("<td> SSL Configuration File: </td>");
					if( sslConfigProp != null){
						out.println("<td> <input type='text' id='pref_sslConfigProp'  name='"+sslConfigProp.getPrefName()+"' value='"+sslConfigProp.getPrefValue()+"' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'"+sslConfigProp.getPreferenceId()+"\',\'SECURITY\',\'pref_sslConfigProp\')\"></span></td>");
					}else{
						out.println("<td> <input type='text' id='pref_sslConfigProp' name='SSL_CONFIG_PROP' value='' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'\',\'SECURITY\',\'pref_sslConfigProp\')\"></span></td>");
					}
				   out.println("</tr>");
				   Preferences trustStore=preferencesDAO.getPreferencesByCategoryName("SECURITY", "TRUST_STORE");
				   out.println("<tr>");
				    out.println("<td> Trust Store: </td>");
					if( trustStore != null){
						out.println("<td> <input type='text' id='pref_trustStore' name='"+trustStore.getPrefName()+"' value='"+trustStore.getPrefValue()+"' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'"+trustStore.getPreferenceId()+"\',\'SECURITY\',\'pref_trustStore\')\"></span></td>");
					}else{
						out.println("<td> <input type='text' id='pref_trustStore' name='TRUST_STORE' value='' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'\',\'SECURITY\',\'pref_trustStore\')\"></span></td>");
					}
				   out.println("</tr>");
				  
				   Preferences trustStorePwd=preferencesDAO.getPreferencesByCategoryName("SECURITY", "TRUST_STORE_PASSWORD");
				   out.println("<tr>");
				    out.println("<td> Trust Store Password: </td>");
					if( trustStorePwd != null){
						out.println("<td> <input type='password' id='pref_trustStorePwd' name='"+trustStorePwd.getPrefName()+"' value='"+trustStorePwd.getPrefValue()+"' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'"+trustStorePwd.getPreferenceId()+"\',\'SECURITY\',\'pref_trustStorePwd\')\"></span></td>");
						
					}else{
						out.println("<td> <input type='password' id='pref_trustStorePwd' name='TRUST_STORE_PASSWORD' value='' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'\',\'SECURITY\',\'pref_trustStorePwd\')\"></span></td>");
					}
				   out.println("</tr>");
				   
				   Preferences keyStore=preferencesDAO.getPreferencesByCategoryName("SECURITY", "KEY_STORE");
				   out.println("<tr>");
				    out.println("<td> Key Store: </td>");
					if( keyStore != null){
						out.println("<td> <input type='text' id='pref_keyStore' name='"+keyStore.getPrefName()+"' value='"+keyStore.getPrefValue()+"' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'"+keyStore.getPreferenceId()+"\',\'SECURITY\',\'pref_keyStore\')\"></span></td>");
					}else{
						out.println("<td> <input type='text' id='pref_keyStore' name='KEY_STORE' value='' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'\',\'SECURITY\',\'pref_keyStore\')\"></span></td>");
					}
				   out.println("</tr>");
				   
				   Preferences keyStorePwd=preferencesDAO.getPreferencesByCategoryName("SECURITY", "KEY_STORE_PASSWORD");
				   out.println("<tr>");
				    out.println("<td> Trust Store Password: </td>");
					if( keyStorePwd != null){
						out.println("<td> <input type='password'  id='pref_keyStorePwd' name='"+keyStorePwd.getPrefName()+"' value='"+keyStorePwd.getPrefValue()+"' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'"+keyStorePwd.getPreferenceId()+"\',\'SECURITY\',\'pref_keyStorePwd\')\"></span></td>");
					}else{
						out.println("<td> <input type='password' id='pref_keyStorePwd' name='KEY_STORE_PASSWORD' value='' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'\',\'SECURITY\',\'pref_keyStorePwd\')\"></span></td>");
					}
				   out.println("</tr>");
				%>
			</table>
		</div>
	</div>
</div>
<div class="column">
	<div class="portlet">
		<div class="portlet-header">
			Administration
		</div>
		<div class="portlet-content">
			<table width="100%">
				<tr><td> 
						<input type='hidden' name="CATEGORY" value="ADMINISTRATION"/>
					</td><td></td></tr>
				<%
					Preferences disableWasNotify=preferencesDAO.getPreferencesByCategoryName("ADMINISTRATION", "DISABLE_WAS_NOTIFICATION");
				    out.println("<tr>");
				    out.println("<td> Disable Was Notification: </td>");
					if( disableWasNotify != null){
						out.println("<td> <input type='text' id='pref_disableWasNotify' name='"+disableWasNotify.getPrefName()+"' value='"+disableWasNotify.getPrefValue()+"' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'"+scriptPathPref.getPreferenceId()+"\',\'ADMINISTRATION\',\'pref_disableWasNotify\')\"></span></td>");
					}else{
						out.println("<td> <input type='text' id='pref_disableWasNotify' name='DISABLE_WAS_NOTIFICATION' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'\',\'ADMINISTRATION\',\'pref_disableWasNotify\')\"></span></td>");
					}
				   
				   out.println("</tr>");
				   
				   Preferences wasInstallPath=preferencesDAO.getPreferencesByCategoryName("ADMINISTRATION", "WAS_INSTALL_PATH");
				    out.println("<tr>");
				    out.println("<td> WAS Install path: </td>");
					if( wasInstallPath != null){
						out.println("<td> <input type='text' id='pref_wasInstallPath' name='"+wasInstallPath.getPrefName()+"' value='"+wasInstallPath.getPrefValue()+"' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'"+wasInstallPath.getPreferenceId()+"\',\'ADMINISTRATION\',\'pref_wasInstallPath\')\"></span></td>");
					}else{
						out.println("<td> <input type='text' id='pref_wasInstallPath' name='WAS_INSTALL_PATH' class='text ui-widget-content ui-corner-all' /></td>");
						out.println("<td><span class='ui-icon  ui-icon-disk' title='update' onClick=\"updateOrAddPreference(\'\',\'ADMINISTRATION\',\'pref_wasInstallPath\')\"></span></td>");
					}
				   
				   out.println("</tr>");
				   
				   
				%>
			</table>
		</div>
	</div>
</div>